import get from '@dfeidao/atom-web/local/get';
import remove from '@dfeidao/atom-web/local/remove';
import fire from '@dfeidao/atom-web/msg/fire';
import nodejs from '@dfeidao/atom-web/msg/nodejs';
import error from '@dfeidao/atom-web/msgbox/error';
import success from '@dfeidao/atom-web/msgbox/success';
import { IFeidaoAiBrowserComponent } from '@dfeidao/web/interfaces';
import hide_loading from '../../atom/hide-loading';
import show_loading from '../../atom/show-loading';

interface Aa {
	group_id: string;
}
export default async function a010(fd: IFeidaoAiBrowserComponent) {

	const productid = get(fd, 'productid');
	//  删除
	const role_allot_id = get(fd, 'role_allot_id');
	if (!role_allot_id) {
		error('请选择角色关联权限');
		return;
	}
	const allot_group = get(fd, 'allot_group') as Aa;
	if (!allot_group) {
		error('请选择条件组');
		return;
	}
	const group_id = allot_group.group_id;
	const query = { productid, role_allot_id, group_id };
	show_loading();
	const count = await nodejs('roler/zj-000004/s011', query);
	hide_loading();
	if (count === 0) {

		error('非合并后的分配条件组');
		return;
	}
	const c_boxs = fd.data.node.querySelectorAll('[data-feidao-name="list_checkbox"]:checked');
	const ids = Array.from(c_boxs).map((item) => {
		return item.getAttribute('data-feidao-id4');
	});
	show_loading();
	const res = await nodejs('roler/zj-000004/s012', query);
	hide_loading();
	if (res === 'success') {
		fire('zj-000004', 'ec-005', role_allot_id, 2, ids);
		remove(fd, 'allot_group');
		success('还原成功');
	} else {
		error('还原失败');
	}
}
